from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-10-02 14:12:21.774667
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 02, Oct, 2021
Time: 14:12:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4747
Nobs: 432.000 HQIC: -46.9877
Log likelihood: 4794.79 FPE: 2.80678e-21
AIC: -47.3223 Det(Omega_mle): 2.28435e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.428597 0.091308 4.694 0.000
L1.Burgenland 0.105121 0.047285 2.223 0.026
L1.Kärnten -0.113296 0.023750 -4.770 0.000
L1.Niederösterreich 0.149711 0.101220 1.479 0.139
L1.Oberösterreich 0.115616 0.099600 1.161 0.246
L1.Salzburg 0.286420 0.049834 5.747 0.000
L1.Steiermark 0.035267 0.066193 0.533 0.594
L1.Tirol 0.105995 0.052340 2.025 0.043
L1.Vorarlberg -0.101448 0.046947 -2.161 0.031
L1.Wien -0.005447 0.090790 -0.060 0.952
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014052 0.208206 0.067 0.946
L1.Burgenland -0.049940 0.107822 -0.463 0.643
L1.Kärnten 0.037647 0.054155 0.695 0.487
L1.Niederösterreich -0.211766 0.230807 -0.917 0.359
L1.Oberösterreich 0.494231 0.227115 2.176 0.030
L1.Salzburg 0.305361 0.113636 2.687 0.007
L1.Steiermark 0.105738 0.150937 0.701 0.484
L1.Tirol 0.311522 0.119349 2.610 0.009
L1.Vorarlberg 0.000065 0.107051 0.001 1.000
L1.Wien 0.005061 0.207024 0.024 0.980
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243685 0.046253 5.269 0.000
L1.Burgenland 0.089096 0.023953 3.720 0.000
L1.Kärnten -0.003606 0.012031 -0.300 0.764
L1.Niederösterreich 0.207311 0.051274 4.043 0.000
L1.Oberösterreich 0.155628 0.050453 3.085 0.002
L1.Salzburg 0.038656 0.025244 1.531 0.126
L1.Steiermark 0.025514 0.033531 0.761 0.447
L1.Tirol 0.067424 0.026513 2.543 0.011
L1.Vorarlberg 0.061023 0.023781 2.566 0.010
L1.Wien 0.116619 0.045990 2.536 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186332 0.045053 4.136 0.000
L1.Burgenland 0.046084 0.023331 1.975 0.048
L1.Kärnten -0.006314 0.011718 -0.539 0.590
L1.Niederösterreich 0.142349 0.049943 2.850 0.004
L1.Oberösterreich 0.318410 0.049144 6.479 0.000
L1.Salzburg 0.100052 0.024589 4.069 0.000
L1.Steiermark 0.128648 0.032660 3.939 0.000
L1.Tirol 0.076886 0.025825 2.977 0.003
L1.Vorarlberg 0.056455 0.023164 2.437 0.015
L1.Wien -0.048950 0.044797 -1.093 0.275
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207823 0.089477 2.323 0.020
L1.Burgenland -0.048193 0.046337 -1.040 0.298
L1.Kärnten -0.032970 0.023273 -1.417 0.157
L1.Niederösterreich 0.112959 0.099190 1.139 0.255
L1.Oberösterreich 0.173475 0.097603 1.777 0.076
L1.Salzburg 0.251241 0.048835 5.145 0.000
L1.Steiermark 0.076590 0.064865 1.181 0.238
L1.Tirol 0.122286 0.051290 2.384 0.017
L1.Vorarlberg 0.115442 0.046006 2.509 0.012
L1.Wien 0.025415 0.088969 0.286 0.775
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.038394 0.069143 0.555 0.579
L1.Burgenland 0.021020 0.035806 0.587 0.557
L1.Kärnten 0.054746 0.017984 3.044 0.002
L1.Niederösterreich 0.206104 0.076648 2.689 0.007
L1.Oberösterreich 0.337140 0.075422 4.470 0.000
L1.Salzburg 0.047061 0.037737 1.247 0.212
L1.Steiermark -0.007200 0.050124 -0.144 0.886
L1.Tirol 0.112458 0.039634 2.837 0.005
L1.Vorarlberg 0.069386 0.035550 1.952 0.051
L1.Wien 0.122249 0.068750 1.778 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197260 0.084564 2.333 0.020
L1.Burgenland 0.013004 0.043793 0.297 0.767
L1.Kärnten -0.057536 0.021995 -2.616 0.009
L1.Niederösterreich -0.126098 0.093744 -1.345 0.179
L1.Oberösterreich 0.195768 0.092244 2.122 0.034
L1.Salzburg 0.035338 0.046154 0.766 0.444
L1.Steiermark 0.286635 0.061304 4.676 0.000
L1.Tirol 0.490427 0.048474 10.117 0.000
L1.Vorarlberg 0.077277 0.043479 1.777 0.076
L1.Wien -0.109468 0.084084 -1.302 0.193
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156722 0.092392 1.696 0.090
L1.Burgenland -0.012564 0.047846 -0.263 0.793
L1.Kärnten 0.063542 0.024032 2.644 0.008
L1.Niederösterreich 0.195927 0.102421 1.913 0.056
L1.Oberösterreich -0.123676 0.100783 -1.227 0.220
L1.Salzburg 0.233378 0.050426 4.628 0.000
L1.Steiermark 0.149314 0.066978 2.229 0.026
L1.Tirol 0.047754 0.052961 0.902 0.367
L1.Vorarlberg 0.130214 0.047504 2.741 0.006
L1.Wien 0.161362 0.091868 1.756 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480739 0.050198 9.577 0.000
L1.Burgenland -0.008082 0.025996 -0.311 0.756
L1.Kärnten -0.009540 0.013057 -0.731 0.465
L1.Niederösterreich 0.204086 0.055647 3.668 0.000
L1.Oberösterreich 0.253372 0.054757 4.627 0.000
L1.Salzburg 0.024120 0.027397 0.880 0.379
L1.Steiermark -0.021527 0.036390 -0.592 0.554
L1.Tirol 0.066101 0.028775 2.297 0.022
L1.Vorarlberg 0.060972 0.025810 2.362 0.018
L1.Wien -0.047830 0.049913 -0.958 0.338
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020283 0.080783 0.139268 0.131779 0.046273 0.074169 -0.002240 0.188002
Kärnten 0.020283 1.000000 -0.043183 0.130218 0.048554 0.071521 0.452226 -0.089726 0.088846
Niederösterreich 0.080783 -0.043183 1.000000 0.282604 0.082303 0.267061 0.031093 0.136165 0.261713
Oberösterreich 0.139268 0.130218 0.282604 1.000000 0.176837 0.287948 0.157807 0.100925 0.135116
Salzburg 0.131779 0.048554 0.082303 0.176837 1.000000 0.126182 0.057282 0.106681 0.049760
Steiermark 0.046273 0.071521 0.267061 0.287948 0.126182 1.000000 0.131468 0.090686 -0.014511
Tirol 0.074169 0.452226 0.031093 0.157807 0.057282 0.131468 1.000000 0.049723 0.120126
Vorarlberg -0.002240 -0.089726 0.136165 0.100925 0.106681 0.090686 0.049723 1.000000 -0.047431
Wien 0.188002 0.088846 0.261713 0.135116 0.049760 -0.014511 0.120126 -0.047431 1.000000